package com.fenghongzhang.day005;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


/**
 * A simple {@link Fragment} subclass.
 */
public class Left_Fragment extends Fragment {
    private EditText lEdit;
    private Button lSend;
    public Left_Fragment() {
        // Required empty public constructor
    }

    private MyListener myListener;

    public interface MyListener{
        void sendMessage(String s);
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_left_, container, false);


        myListener = (MyListener) getActivity().getSupportFragmentManager().findFragmentByTag("right");




        lEdit = (EditText) inflate.findViewById(R.id.l_edit);
        lSend = (Button) inflate.findViewById(R.id.l_send);

        lSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = lEdit.getText().toString();
                myListener.sendMessage(s);
            }
        });


        return inflate;
    }
}
